package com.example.covid.Utils;

/**
 * 工具类
 * @author KamenRider
 */
public class Result<T> {

    /**
     * 返回码，0成功
     */
    private Integer code;
    /**
     * 返回描述
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;
    /**
     * 分页查询的总记录数
     */
    private Long count;

    private Result() {
    }

    private Result(Integer code, String message, T data, Long count) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

    public static Result<Object> success(){
        // 0表示成功
        return new Result(0,"success",null,null);
    }
    public static Result<Object> success(String message){
        // 0表示成功
        return new Result(0,message,null,null);
    }
    public static Result<Object> success(Object data,Long count){
        // 0表示成功
        return new Result(0,"success",data,count);
    }
    public static Result<Object> fail(){
        // -1失败
        return new Result(-1,"fail",null,null);
    }
    public static Result<Object> fail(String message){
        // -1失败
        return new Result(-1,message,null,null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                ", count=" + count +
                '}';
    }
}
